package com.ybdz.scanner.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

import com.ybdz.scanner.R;
import com.ybdz.scanner.base.BaseActivity;
import com.ybdz.scanner.utils.MyApplication;
import com.ybdz.scanner.utils.SPUtils;


/**
 * @ClassName: WelcomeActivity
 * @author: zhao
 * @Description:    欢迎界面
 * @date 2017/12/25 13:38
 */
public class WelcomeActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉标题栏
        this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        //设置全屏
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_welcome);
        handleWelcome();
    }

    /**
     * 处理欢迎页面
     */
    private void handleWelcome() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                String name = SPUtils.getString(WelcomeActivity.this, "usename", "deUseName");
                if (!name.equals("deUseName") ){
//                    MyApplication.setIsLogin(true);
//                    SPUtils.saveBoolean(WelcomeActivity.this,"ISLOGIN",true);
                    startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                }else {
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                }
                WelcomeActivity.this.finish();
            }
        }, 1500);
    }

    @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         if(keyCode == KeyEvent.KEYCODE_BACK){
             return  true;
         }
         return  super.onKeyDown(keyCode, event);
         }
}
